<?
	class InputText extends Input
	{
		var $nLength;
		var $nSize;
		var $nCase;
		var $bEditor;
		var $bPassword;
		var $bAutoSize = true;
		var $bEditable = false;
		var $bMultilanguage= false;
		var $nMultilanguageStyle= MULTILANGUAGE_EN_CAPAS;

	function setEditable ( $cUrl  )
	{
		$this->bEditable = true;
		//$this->setOnKeyPress ( " return keyPressLookUp( event  ); ");
		//$this->setOnKeyUp ( "changeLookUp( \"" . $this->cField . "\", \"$cUrl\", event , \"" . $this->cField . "\", \"delaySendInputText\" );" );
		//$this->setOnKeyDown( "return keydownLookUp( \"" . $this->cField . "\", \"$cUrl\", event , \"" . $this->cField . "\");" );
		
		$this->setOnKeyPress ( " return keyPressLookUp( event  ); ");
		$cEvent = "changeLookUp( \"" . $this->cField . "\", \"$cUrl\", event , \"" . $this->cField . "\", \"delaySendInputText\" );";
		$this->setOnKeyUp ( $cEvent );
		$cEvent = "return keydownLookUp( \"" . $this->cField . "\", \"$cUrl\", event, \"" . $this->cField . "\" );";
		$this->setOnKeyDown( $cEvent );
	}
	
	function setMultilanguage( $bMultilanguage = true )
		{
			$this->bMultilanguage = $bMultilanguage;
		}
	function setMultilanguageStyle( $nMultilanguageStyle)
		{
			$this->bMultilanguage = true;
			$this->nMultilanguageStyle = $nMultilanguageStyle;
		}

	function setPassword ( $bPassword = true )
		{
			$this->bPassword = $bPassword;
		}

	function setDomain( $cDomain )
		{
			if ( substr( $cDomain , 0, 3 )  == "www" ) $cDomain = substr( $cDomain, 4 );
			$this->setOnKeyPress ( "return checkEmailEdit( this, \"$cDomain\" , event );" );
		}

	function InputText( $cLabel, $cField, $cValue = '', $bMandatory = false, $bEditor = false, $nLength = '', $nCase = SET_CASE_NORMAL )
		{
			$this->Input($cLabel, $cField, $cValue, $bMandatory );

			// Si es MultiLanguage  y vienen las despcripciones divididas => Las une entre tags, por ej <es></es>
			$cLanguageSel = getParam( $cField . "_lang" ) ;
			$cLanguage = getParam( $cField . "_es" ) ;
			if (  $cLanguageSel  || $cLanguage)
			{
				global $aLanguage;
				$cValue = '';
				foreach ( $aLanguage as $aItem )
				{
					$cParametro = ($aItem[0] == $cLanguageSel ) ?  $cField :  $cField . "_"  . $aItem[0]  ;
					$cValue .= "<" . $aItem[0] . ">" . getParam( $cParametro )  . "</". $aItem[0]. ">";
				}
				$this->cValue = $cValue;
			}
			$this->nCase = $nCase;
			if ( $bEditor )
			{
				$this->setEditor( $bEditor );
			}
			$this->bPassword = false;
			$this->setLength( $nLength );
		}
	function setEditor( $bOn = true, $nqCol = 80, $nqRow = 0 )
		{
			if ( EDITOR ) 
			{
				$oModBase =& loadModule("base");
				$oModBase->addScript ( "texteditor.js" );
				$this->bEditor = $bOn;
				$nqRow = ( $this->nLength && $nqRow == 0 ) ? ceil( $this->nLength / $nqCol ) : 24;
				$this->nqCol = $nqCol;
				$this->nqRow = $nqRow;
			} else $this->setLength(4092);
		}
	function make()
		{
			// Si esta setea como Oculto
				if ( $this->bHidden ) return parent::make();
			$cValue = $this->getValue();
			$cValue = str_replace( '"', '&quot;' , $cValue );
			$this->setOnBlur( "return checkText(this, \"" . $this->cLabel . "\" , " . ($this->bMandatory ? 1:0) . " );", true );
			// Toma el estilo del Input y lo mueve a una variable
			$cPropiedades = $this->getProperties();
			if ( $this->nSize ) $cPropiedades .= " size='" . $this->nSize . "' ";
			if ( $this->nLength ) $cPropiedades .= " maxlength='" . $this->nLength . "' ";
			// Si es Multilenguage => parse del Value y arma los input
			if ( $this->bMultilanguage )
			{
				global $aLanguage;
				foreach ( $aLanguage as $aItem )
				{
					$nPosDesde = strpos ( $cValue, "<" . $aItem[0] . ">" );
					$nPosHasta  = strpos ( $cValue, "</" . $aItem[0] . ">" );
					$cValueItem = ( $nPosDesde === FALSE || $nPosHasta === FALSE) ?  '': substr( $cValue, $nPosDesde +  4 , $nPosHasta  - $nPosDesde  - 4 ) ;
					if ($aItem[0] == 'es' ) $cValueSel = $cValueItem;
					if ( $this->nMultilanguageStyle == 1 || $this->bEditor)
					{
						$cMultilanguage .= "&nbsp;<input type=\"hidden\" name=\"" . $this->cField  . "_" . $aItem[0]."\" value=\"" . ($aItem[0] == 'es' ? '': $cValueItem) . "\" />";
					} else
					{
						if ( $this->nLength <= 255 )
						{
							if ( $this->cWidth  ) $this->addStyle( " width:" . $this->cWidth . "px;" );
							$this->setOnKeyPress ( "return checkTextEdit(this, " . $this->nCase . ", event);" );
							$cMultilanguage .= "&nbsp;<input " . $this->getStyleHTML() . "  $cPropiedades " . $this->getEvents() . "  type=\"text\" name=\"" . $this->cField  . "_" . $aItem[0]."\" value=\"" . $cValueItem . "\" />" ;
							$cMultilanguage .= "<img alt='". $aItem[1] . "' class='accion0' src='" . URL_IMAGES . "/".  $aItem[2] . "' /><br/>" ;
						} else
						{
							$nMaximo = $this->nLength - 1;
							$this->addStyle( "width:" . ($this->cWidth ? $this->cWidth: 550) . "px;"  );
							$cMultilanguage .= "<img alt='". $aItem[1] . "' class='accion0' src='" . URL_IMAGES . "/".  $aItem[2] . "' /><br/>" ;
							$cMultilanguage.=  "<textarea " . $this->getStyleHTML() . " rows='4' " . $this->getEvents() . "  name=\"" . $this->cField  . "_" . $aItem[0]."\" name=\"" . $this->cField  . "_" . $aItem[0]."\" onkeypress='if(this.value.length > $nMaximo && event.which != 8 && event.which != 46 ) return false;'>" . $cValueItem . "</textarea>";
						}
					}
				}
				if ( $this->nMultilanguageStyle == 1 || $this->bEditor)
				{
					$cMultilanguage .= "<input type=\"hidden\" name=\"" . $this->cField  . "_lang\" value=\"es\" />";
				}
				// Deja en el Input el Valor del Seleccionado
				if ( !(strpos ( $cValue, "<es>" ) === FALSE) ) $cValue = $cValueSel;
			}
			// Si esta seteado el  Editor
			if ( $this->bEditor )
			{
				$cField = $this->cField;
				$nHeight = 150;
				if ( !$this->cWidth ) $this->cWidth =  550;
				$cPath = URL_IMAGES  . '/editor/';
				$cPathImages = URL_IMAGES . '/editor/';
				$bButtons = true;
				$bReadOnly = false;
				$cReturn = "<div class=\"editor\">";
				if ($bButtons == true)
				{
					$cReturn .= "<table class=\"editor_back\" cellpadding=2 cellspacing=0 id=\"Buttons1_$cField\" width=\"". $this->cWidth . "\"><tr><td><select style=\"width: 55px;\" id=\"formatblock_$cField\" onchange=\"selectFont('$cField', this.id);\"><option value=\"\">Style</option><option value=\"<p>\">Paragraph &lt;p&gt;</option><option value=\"<h1>\">Heading 1 &lt;h1&gt;</option><option value=\"<h2>\">Heading 2 &lt;h2&gt;</option><option value=\"<h3>\">Heading 3 &lt;h3&gt;</option><option value=\"<h4>\">Heading 4 &lt;h4&gt;</option><option value=\"<h5>\">Heading 5 &lt;h5&gt;</option><option value=\"<h6>\">Heading 6 &lt;h6&gt;</option><option value=\"<address>\">Address &lt;ADDR&gt;</option><option value=\"<pre>\">Formatted &lt;pre&gt;</option></select></td><td><select style=\"width: 55px;\" id=\"fontname_$cField\" onchange=\"selectFont('$cField', this.id)\"><option value=\"Font\" selected>Font</option><option value=\"Arial, Helvetica, sans-serif\">Arial</option><option value=\"Courier New, Courier, mono\">Courier New</option><option value=\"Times New Roman, Times, serif\">Times New Roman</option><option value=\"Verdana, Arial, Helvetica, sans-serif\">Verdana</option>\"<option value=\"georgia,Times New Roman,times,serif\">Georgia</option>\"<option value=\"tahoma,arial,helvetica,sans-serif\">Tahoma</option>\"<option value=\"impact\">Impact</option>\"<option value=\"wingdings\">WingDings</option>\"</select></td><td><select style=\"width: 50px;\" unselectable=\"on\" id=\"fontsize_$cField\" onchange=\"selectFont('$cField', this.id);\"><option value=\"Size\">Size</option><option value=\"1\">1 ( 8 pt)</option><option value=\"2\">2 (10 pt)</option><option value=\"3\">3 (12 pt)</option><option value=\"4\">4 (14 pt)</option><option value=\"5\">5 (18 pt)</option><option value=\"6\">6 (24 pt)</option><option value=\"7\">7 (36 pt)</option></select></td><td><img id=\"bold\" class=\"editor_imagen\" src=\"$cPathImages/bold.gif\" width=\"16\" height=\"16\" alt=\"Bold\" title=\"Bold\" onclick=\"rteCommand('$cField', 'bold', '')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/italic.gif\" width=\"16\" height=\"16\" alt=\"Italic\" title=\"Italic\" onclick=\"rteCommand('$cField', 'italic', '')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/underline.gif\" width=\"16\" height=\"16\" alt=\"Underline\" title=\"Underline\" onclick=\"rteCommand('$cField', 'underline', '')\"></td><td><img class=\"editor_separador\" src=\"$cPathImages/blackdot.gif\" width=\"1\" height=\"16\" border=\"0\" alt=\"\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/left_just.gif\" width=\"16\" height=\"16\" alt=\"Align Left\" title=\"Align Left\" onclick=\"rteCommand('$cField', 'justifyleft', '')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/centre.gif\" width=\"16\" height=\"16\" alt=\"Center\" title=\"Center\" onclick=\"rteCommand('$cField', 'justifycenter', '')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/right_just.gif\" width=\"16\" height=\"16\" alt=\"Align Right\" title=\"Align Right\" onclick=\"rteCommand('$cField', 'justifyright', '')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/justifyfull.gif\" width=\"16\" height=\"16\" alt=\"Justify Full\" title=\"Justify Full\" onclick=\"rteCommand('$cField', 'justifyfull', '')\"></td><td><img class=\"editor_separador\" src=\"$cPathImages/blackdot.gif\" width=\"1\" height=\"16\" border=\"0\" alt=\"\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/numbered_list.gif\" width=\"16\" height=\"16\" alt=\"Ordered List\" title=\"Ordered List\" onclick=\"rteCommand('$cField', 'insertorderedlist', '')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/list.gif\" width=\"16\" height=\"16\" alt=\"Unordered List\" title=\"Unordered List\" onclick=\"rteCommand('$cField', 'insertunorderedlist', '')\"></td><td><img class=\"editor_separador\" src=\"$cPathImages/blackdot.gif\" width=\"1\" height=\"16\" border=\"0\" alt=\"\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/outdent.gif\" width=\"16\" height=\"16\" alt=\"Outdent\" title=\"Outdent\" onclick=\"rteCommand('$cField', 'outdent', '')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/indent.gif\" width=\"16\" height=\"16\" alt=\"Indent\" title=\"Indent\" onclick=\"rteCommand('$cField', 'indent', '')\"></td><td><div id=\"forecolor_$cField\"><img class=\"editor_imagen\" src=\"$cPathImages/textcolor.gif\" width=\"16\" height=\"16\" alt=\"Text Color\" title=\"Text Color\" onclick=\"dlgColorPalette('$cField', 'forecolor', '')\"></div></td><td><div id=\"hilitecolor_$cField\"><img class=\"editor_imagen\" src=\"$cPathImages/bgcolor.gif\" width=\"16\" height=\"16\" alt=\"Background Color\" title=\"Background Color\" onclick=\"dlgColorPalette('$cField', 'hilitecolor', '')\"></div></td><td><img class=\"editor_separador\" src=\"$cPathImages/blackdot.gif\" width=\"1\" height=\"16\" border=\"0\" alt=\"\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/hyperlink.gif\" width=\"16\" height=\"16\" alt=\"Insert Link\" title=\"Insert Link\" onclick=\"dlgInsertLink( '$cPath/', '$cField', 'link')\"></td><td><div id=\"table_$cField\"><img class=\"editor_imagen\" src=\"$cPathImages/insert_table.gif\" width=\"16\" height=\"16\" alt=\"Insert Table\" title=\"Insert Table\" onclick=\"dlgInsertTable( '$cPath/', '$cField', 'table', '')\"></div></td><td><img class=\"editor_separador\" src=\"$cPathImages/blackdot.gif\" width=\"1\" height=\"16\" border=\"0\" alt=\"\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/undo.gif\" width=\"16\" height=\"16\" alt=\"Undo\" title=\"Undo\" onclick=\"rteCommand('$cField', 'undo')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/redo.gif\" width=\"16\" height=\"16\" alt=\"Redo\" title=\"Redo\" onclick=\"rteCommand('$cField', 'redo')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/justifyfull.gif\" width=\"16\" height=\"16\" alt=\"Sin Formato\" title=\"Sin Formato\" onclick=\"oField = document.getElementById('$cField'); alert(oField.innerHTML ) ; oField.innerHTML = oField.innerText;\"></td></tr></table>";
					/*<table class=\"editor_back\" cellpadding=\"0\" cellspacing=\"1px\" id=\"Buttons2_$cField\" width=\"$cWidth\"><tr><td><img class=\"editor_imagen\" src=\"$cPathImages/hr.gif\" width=\"16\" height=\"16\" alt=\"Horizontal Rule\" title=\"Horizontal Rule\" onclick=\"rteCommand('$cField', 'inserthorizontalrule', '')\"></td><td><img class=\"editor_separador\" src=\"$cPathImages/blackdot.gif\" width=\"1\" height=\"16\" border=\"0\" alt=\"\"></td><td><div id=\"table_$cField\"><img class=\"editor_imagen\" src=\"$cPathImages/image.gif\" width=\"16\" height=\"16\" alt=\"Insert Image\" title=\"Insert Image\" onclick=\"dlgInsertImage( '$cPath/', '$cField', 'table', '')\"></div></td><td><img class=\"editor_imagen\" src=\"$cPathImages/spellcheck.gif\" width=\"16\" height=\"16\" alt=\"Spell Check\" title=\"Spell Check\" onclick=\"checkspell()\"></td><td width=\"100%\"></td></tr></table><td><img class=\"editor_separador\" src=\"$cPathImages/blackdot.gif\" width=\"1\" height=\"16\" border=\"0\" alt=\"\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/cut.gif\" width=\"16\" height=\"16\" alt=\"Cut\" title=\"Cut\" onclick=\"rteCommand('$cField', 'cut')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/copy.gif\" width=\"16\" height=\"16\" alt=\"Copy\" title=\"Copy\" onclick=\"rteCommand('$cField', 'copy')\"></td><td><img class=\"editor_imagen\" src=\"$cPathImages/paste.gif\" width=\"16\" height=\"16\" alt=\"Paste\" title=\"Paste\" onclick=\"rteCommand('$cField', 'paste')\"></td>*/
				}
				$cReturn .= "<iframe $cPropiedades " . $this->getEvents() . " id=\"$cField\" name=\"$cField\" width=\"" . $this->cWidth . "\" height=\"$nHeight\" src=\"$cPathImages/blank.htm\"></iframe>";
				if ( !$bReadOnly) $cReturn .= "<input type=\"hidden\" id=\"chkSrc$cField\" onclick=\"toggleHTMLSrc('$cField','$bButtons');\" />&nbsp;"; //<label for=\"chkSrc$cField\">Ver HTML</label>";
				$cReturn .= "<iframe onload=\"enableDesignMode( '$cField', '$bReadOnly');\" width=\"154\" height=\"104\" id=\"cp$cField\" src=\"$cPath/palette.htm\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" style=\"visibility:hidden; position: absolute;\"></iframe>";
				$cReturn .= "<textarea style='display:none' id=\"hdn$cField\" name=\"$cField\">". $cValue . "</textarea></div>";
				if ( $this->bMultilanguage ) $cReturn .= $cMultilanguage;
				return $cReturn;
				//return "<textarea rows='" . $this->nqRow . "' cols='. $this->nqCol .' style='width: 100%'  id='" . $this->cField . "' name='" . $this->cField . "' > $cValue </textarea>";
			}
			$cReturn = "";
			// make comun
			if ( $this->nLength <= 255 )
			{
				if ( $cValue == '' && $this->cEmptyText && !$this->bPassword )
				{
					$this->addStyle( "color:#cdcdcd; font-style: italic;" );
					$this->setOnFocus ( ' if ( this.value == "' . $this->cEmptyText . '" ) this.value= ""; this.style.color="#000000"; this.style.fontStyle="normal"; ' );
					$cValue = $this->cEmptyText;
				}
				$cType = ( $this->bPassword ) ? 'password':'text';
				if ( $this->cWidth  ) $this->addStyle( " width:" . $this->cWidth . "px;"  );
				if ( !$this->bEditable ) $this->setOnKeyPress ( "return checkTextEdit(this, " . $this->nCase . ", event);" );
				$cReturn .= "<input " . $this->getStyleHTML() . " type='$cType' $cPropiedades " . $this->getEvents() . " id='" . $this->cField. "' name='" . $this->cField . "' value='$cValue' />";
				// Si tiene Ajax tipo Lookup agrega el div
				if ( $this->bEditable )	$cReturn .= "<div style='width: " . $this->cWidth . "px;' class='divLookup' id='divLookUp_" . $this->cField . "'></div>";			
			} else
			{
				$nMaximo = $this->nLength - 1;
				$this->addStyle( "width:" . ($this->cWidth ? $this->cWidth: 550) . "px;");
				$cReturn .=  "<textarea " . $this->getStyleHTML() . " rows='4' " . $this->getEvents() . "  id='" . $this->cField . "' name='" . $this->cField . "' onkeypress='if(this.value.length > $nMaximo) return false;'>$cValue</textarea>";
			}
			// Agrega el Multilenguaje
			if ( $this->bMultilanguage )
			{
				if ( $this->nMultilanguageStyle == 1 )
					$cReturn .= $cMultilanguage;
				else
					$cReturn = $cMultilanguage;
			}
			return $cReturn;
		}
	function setSize( $nSize )
		{
			$this->nSize = $nSize;
			$this->bAutoSize = false;
		}
	function setLength( $nLength )
		{
			if ( $nLength == '' || !is_numeric($nLength)  ) return false;
			$this->nLength = $nLength;
			// Si no tiene definido el ancho lo setea de escalonadamente por la longitud del campo
			if ( $this->bAutoSize )
			{
				if ( $this->nLength <= 5 )
				{
					$this->nSize = 3;
				} elseif ( $this->nLength <= 60 )
				{
					$this->nSize = 20;
				} else
				{
					$this->nSize = 40;
				}
			}
		}
	}

?>